<template>
	<view class="menu-box left clearfix">
		<view class="menu-breadcrumb left clearfix">
			<uni-breadcrumb separator="/" style="width:300px;float:left;">
			  <uni-breadcrumb-item v-for="(route,index) in routes" :key="index" :to="route.to">
			    {{route.name}}
			  </uni-breadcrumb-item>
			</uni-breadcrumb>
			<!--搜索-->
			<view class="menu-so right clearfix">
				<label class="left">
					<input placeholder="请输入订单号/手机号/姓名查找" v-model="keyword" style="width:250px;font-size:13px;height:30px;line-height:30px;padding-left:5px;" />
				</label>
				<label class="right" style="margin-right:10px;" @click="submitSearch()">
					<uni-icons type="search" size="25" color="#999"></uni-icons>
				</label>
			</view>
		</view>
		
		<view class="menu-content left clearfix">
			<uni-table border stripe emptyText="暂无更多数据" >
				<!-- 表头行 -->
				<uni-tr>
					<uni-th align="center" width="250">订单号</uni-th>
					<uni-th align="center">商品</uni-th>
					<uni-th align="center" width="50">数量</uni-th>
					<uni-th align="center" width="80">运费</uni-th>
					<uni-th align="center">总价</uni-th>
					<uni-th align="center" width="70">支付</uni-th>
					<uni-th align="center">收货人</uni-th>
					<uni-th align="center" width="120">发票</uni-th>
					<uni-th align="center" width="80">下单时间</uni-th>
					<uni-th align="center" width="350">操作</uni-th>
					
				</uni-tr>
				<!-- 表格数据行 -->
				<uni-tr v-for="(item,index) in data">
					<uni-td align="center" style="font-size:14px;">{{item.order_no}}
					<label title="复制" style="margin-left:10px;" @click="copy(item.order_no)">
						<uni-icons type="icon-fuzhi5" custom-prefix="iconfont" size="15" color="#666"></uni-icons>
					</label>
					</uni-td>
					<uni-td align="center" width="250">
						<view class="order-goods left" v-for="(gItem,gIndex) in item.goods.cartList" :style="gIndex != 0?'border-top:1px solid #efefef':'border-top:none;'">
							<view class="order-image left" @click="alertGoodsDetail(item,index)">
								<image :src="gItem.goods_image" style="width:50px;height:50px;"></image>
							</view>
							<view class="order-text left">
								<text><label @click="copy(gItem.param.serial_number)">{{gItem.param.serial_number}}</label> · {{gItem.goods_title.slice(0,13)}}</text>
								<text><label @click="copy(gItem.param.model)">{{gItem.param.model}}</label> <label style="color:#999">{{gItem.param.price}} × {{gItem.param.number}} = {{gItem.param.total_price}}</label></text>
							</view>
						</view>
					</uni-td>
					<uni-td align="center">{{item.number}}</uni-td>
					<uni-td align="center" v-if="item.postage > 0">{{item.postage}}</uni-td>
					<uni-td align="center" v-if="item.postage <= 0" style="color:#00c296;font-size:12px;">免运费</uni-td>
					<uni-td align="center" style="color:#f3a73f;">{{item.pay_total_price}}</uni-td>
					<uni-td align="center"><label v-if="item.is_pay == 0" style="color:#ccc;">--</label><label v-if="item.is_pay == 1" style="color:#00c296;">已支付</label></uni-td>
					<uni-td align="left" width="250"><label style="font-weight:bold;" @click="copy(item.address.mobile)">{{item.address.name}}·{{item.address.mobile}}</label><br><label style="color:#999;font-size:12px;">{{item.address.area[0].text}}{{item.address.area[1].text}}{{item.address.area[2].text}}{{item.address.address.slice(0,50)}}</label></uni-td>
					<uni-td align="center" @click="alertInvoice(item,index)" v-if="item.invoice && item.invoice.type && item.invoice.title">开发票<label v-if="item.is_invoice==true" style="color:#00c296;font-size:12px;">·已开</label> <label style="color:#2979ff;"><uni-icons type="right" size="14" color="#666"></uni-icons></label></uni-td>
					<uni-td align="center" v-if="!item.invoice || !item.invoice.type || !item.invoice.title">--</uni-td>
					<uni-td align="center"><uni-dateformat :date="item.create_date" format="MM-dd hh:mm"></uni-dateformat></uni-td>
					<uni-td align="center">
					<button size="mini" class="list-button"  @click="alertGoodsDetail(item,index)">详情</button>
					<button size="mini" class="list-button" @click="alertInvoice(item,index)" v-if="item.invoice && item.invoice.title">开票</button>
					<button size="mini" class="list-button" disabled v-if="!item.invoice || !item.invoice.title">开票</button>
					<button size="mini" class="list-button" @click="shipment(item,index)" :disabled="item.status_code == 1?false:true">发货</button>
					<button size="mini" class="list-button">打印</button></uni-td>
				</uni-tr>
				
			
			</uni-table>
			
			<view class="list-page left clearfix">
				<uni-pagination :current="currentPage" :total="total" title="标题文字" @change="changePage" />
			</view>
			
		
	</view>
	
	<!--订单详情-->
	<uni-popup type="center" ref="goodsDetail">
		<view class="op-box">
			<view class="op-title">
				订单详情 · <label style="color:#00c296" v-if="currentOrder.is_pay==1">已支付</label><label v-else style="color:red;">未支付</label>
				<label style="margin-left:20px;color:#ff5000;font-size:13px;font-weight:400;" v-if="currentOrder.is_urge >0">已催发货 {{currentOrder.is_urge}} 次</label>
				<view class="op-close" @click="this.$refs.goodsDetail.close()">
					<uni-icons type="closeempty" size="20" color="#666"></uni-icons>
				</view>
			</view>
			
			<!--内容-->
			<view class="op-content">
				<!--订单号和支付时间-->
				<view class="order-no left clearfix">
					<label class="left order-number">{{currentOrder.order_no}} <uni-icons @click="copy(currentOrder.order_no)" type="icon-fuzhi5" custom-prefix="iconfont" size="15" color="#666"></uni-icons></label>
					<label class="right order-create-date">
						<uni-dateformat :date="currentOrder.create_date" format="yyyy-MM-dd hh:mm:ss"></uni-dateformat>
					</label>
				</view>
				
				<!--购买的商品信息-->
				<view class="order-goodss left clearfix">
					<view class="order-titles left clearfix">
						商品列表 <label class="order-title-right right">共 <span style="color:#00c296;">{{currentOrder.number}}</span> 件商品</label>
					</view>
					<view class="order-goods-list left clearfix" v-for="(item,index) in currentOrder.goods.cartList" :style="index!=0?'border-top:1px solid #eee':'border-top:none;'">
						<view class="order-goods-image left clearfix">
							<image :src="item.goods_image" style="width:80px;height:80px;"></image>
						</view>
						<view class="order-goods-text left clearfix">
							<view class="order-goods-text-left left clearfix">
								<text   @click="copy(item.goods_title)">
									{{item.goods_title.slice(0,13)}}
								</text>
								<text style="font-size:13px;color:#999;">型号：<label @click="copy(item.param.model)">{{item.param.model}}</label> 规格：<label @click="copy(item.param.specs)">{{item.param.specs}}</label></text>
								<text style="font-size:13px;color:#999;">
									<label @click="copy(item.param.serial_number)">编号：{{item.param.serial_number}}</label> 
								</text>
							</view>
							<view class="order-goods-text-right right cleafix">
								<view class="order-goods-right-number left">
								 	× ️{{item.param.number}}
								</view>
								<view class="order-goods-right-price right">
									￥{{item.param.total_price}}
								</view>
							</view>
						</view>
					</view>
				</view>
				
				<!--用户信息-->
				<view class="order-userinfo left clearfix">
					<view class="order-titles left clearfix">
						收件人 <label v-if="currentOrder.postage > 0">运费：{{currentOrder.postage}}</label><label v-else style="color:#00c296;">免运费</label>
					</view>
					<view class="order-userinfo-content left clearfix">
						<text>
							<label>
								<uni-icons type="icon-wode19" size="15" color="#999" custom-prefix="iconfont"></uni-icons>
							</label>
							<label @click="copy(currentOrder.address.name)">
								{{currentOrder.address.name}} ·
							</label>
						 <label style="color:#ff5000;" @click="copy(currentOrder.address.mobile)">{{formatPhone(currentOrder.address.mobile,true)}}</label></text>
						<text>
							<label>
								<uni-icons type="icon-dizhi3" size="15" color="#999" custom-prefix="iconfont"></uni-icons>
							</label>
							
							<label>
								{{currentOrder.address.area[0].text}} · {{currentOrder.address.area[1].text}} · {{currentOrder.address.area[2].text}}{{currentOrder.address.address}}
							</label>
						
						</text>
					</view>
				</view>
				
				<!--发票信息-->
				<view class="order-userinfo left clearfix" v-if="currentOrder.invoice && currentOrder.invoice.title">
					<view class="order-titles left clearfix">
						发票信息
					</view>
					<view class="order-userinfo-content left clearfix">
						<text>
								发票类型：{{currentOrder.invoice.type}} 
						 </text>
						<text @click="copy(currentOrder.invoice.title)">
								发票抬头：{{currentOrder.invoice.title}} 
						 </text>
						 <text @click="copy(currentOrder.invoice.number)" v-show="currentOrder.invoice.number">
						 		<label>纳税人号：</label><label style="color:#ff5000;">{{currentOrder.invoice.number}} </label>
						  </text>
						<text @click="copy(currentOrder.invoice.address)" v-show="currentOrder.invoice.address">
								注册地址：{{currentOrder.invoice.address}} 
						 </text>
						 <text @click="copy(currentOrder.invoice.tel)" v-show="currentOrder.invoice.tel">
						 		注册电话：{{currentOrder.invoice.tel}} 
						  </text>
						  
						  <text @click="copy(currentOrder.invoice.blank)" v-show="currentOrder.invoice.blank">
						  		开户银行：{{currentOrder.invoice.blank}} 
						   </text>
						   <text @click="copy(currentOrder.invoice.blank_number)" v-show="currentOrder.invoice.blank_number">
						   		<label>银行卡号：</label><label style="color:#ff5000;">{{currentOrder.invoice.blank_number}} </label>
						    </text>
						 
						 <text>
						 		<label>是否已开票：</label><label style="color:#ff5000;" v-if="currentOrder.is_invoice==false">未开票 </label>
								<label style="color:#00c296;" v-if="currentOrder.is_invoice==true">已开票 </label>
						  </text>
						  
					</view>
				</view>
				
				
				<!--备注-->
				<view class="order-userinfo left clearfix"  v-if="currentOrder.order_notes || currentOrder.notes">
					<view class="order-titles left clearfix" v-if="currentOrder.notes">
						备注
					</view>
					<view class="order-userinfo-content left clearfix" v-if="currentOrder.notes">
						<text v-if="currentOrder.notes">{{currentOrder.notes}}</text>
						<text v-else style="color:#999;">无备注</text>
					</view>
					<view class="order-titles left clearfix" style="margin-top:0;" v-if="currentOrder.order_notes">
						管理员备注
					</view>
					<view class="order-userinfo-content left clearfix" v-if="currentOrder.order_notes">
						<text v-if="currentOrder.order_notes">{{currentOrder.order_notes}}</text>
						<text v-else style="color:#999;">无备注</text>
					</view>
				</view>
				
				
				<!--快递信息-->
				<view class="order-userinfo left clearfix" v-if="currentOrder.delivery && currentOrder.delivery.title">
					<view class="order-titles left clearfix">
						快递信息
					</view>
					<view class="order-userinfo-content left clearfix">
						<text>
								快递公司：{{currentOrder.delivery.title}} 
						 </text>
						<text @click="copy(currentOrder.delivery.number)">
								快递单号：{{currentOrder.delivery.number}}
						 </text>
						 <text @click="copy(currentOrder.delivery.create_date)">
						 		<label style="float:left;">发货时间：</label><label style="float:left;width:300px;"><uni-dateformat :date="currentOrder.delivery.create_date" format="yyyy-MM-dd hh:mm:ss"></uni-dateformat></label>
						  </text>
						  
					</view>
				</view>
				
				
				
			</view>
			
			<!--底部菜单-->
			<view class="order-buttom-box left clearfix">
				<view class="order-buttom-goods-number left">
					共 {{currentOrder.number}} 件商品
				</view>
				
				<view class="order-buttom-goods-number left">
					运费： <label v-if="currentOrder.postage > 0">￥{{currentOrder.postage}}</label><label v-else style="color:#00c296;">免运费</label>
				</view>
				
				<view class="order-buttom-price right">
					<label>总价：</label>
					<label style="color:#ff5000">￥{{currentOrder.goods.totalPrice}}(原价)</label>
					<label v-if="currentOrder.postage > 0">+</label>
					<label style="color:#ff5000" v-if="currentOrder.postage > 0">￥{{currentOrder.postage}}(运费)</label>
					<label v-if="currentOrder.discount > 0">-</label>
					<label  v-if="currentOrder.discount > 0" style="color:#ff5000">￥{{currentOrder.discount}}(优惠金额)</label>
					<label>=</label>
					<label style="color:#ff5000">￥{{currentOrder.pay_total_price}}(支付金额)</label>
				</view>
			</view>
		</view>
	</uni-popup>
	<!--弹出发票信息-->
	<uni-popup type="center" ref="alertInvoice">
		<view class="op-box" style="height:500px;">
			<view class="op-title">
				开票信息
				<view class="op-close" @click="this.$refs.alertInvoice.close()">
					<uni-icons type="closeempty" size="20" color="#666"></uni-icons>
				</view>
			</view>
			
			<view class="op-content">
				<view class="order-userinfo-content left clearfix">
					<text>
							发票类型：{{invoice.invoice.type}} 
					 </text>
					<text @click="copy(invoice.invoice.title)">
							发票抬头：{{invoice.invoice.title}} 
					 </text>
					 <text @click="copy(invoice.invoice.number)" v-show="invoice.invoice.number">
					 		<label>纳税人号：</label><label style="color:#ff5000;">{{invoice.invoice.number}} </label>
					  </text>
					<text @click="copy(invoice.invoice.address)" v-show="invoice.invoice.address">
							注册地址：{{invoice.invoice.address}} 
					 </text>
					 <text @click="copy(invoice.invoice.tel)" v-show="invoice.invoice.tel">
					 		注册电话：{{invoice.invoice.tel}} 
					  </text>
					  
					  <text @click="copy(invoice.invoice.blank)" v-show="invoice.invoice.blank">
					  		开户银行：{{invoice.invoice.blank}} 
					   </text>
					   <text @click="copy(invoice.blank_number)" v-show="invoice.invoice.blank_number">
					   		<label>银行卡号：</label><label style="color:#ff5000;">{{invoice.invoice.blank_number}} </label>
					    </text>
					 
					 <text>
					 		<label>是否已开票：</label><label style="color:#ff5000;" v-if="invoice.is_invoice==false">未开票 </label>
							<label style="color:#00c296;" v-if="invoice.is_invoice==true">已开票 </label><label v-if="invoicePercent < 100 && invoicePercent > 0" style="color:#00c296;">上传中{{invoicePercent}}%</label>
					  </text>
					  
				</view>
				
				<view class="po-buttom-box left clearfix" @click="uploadInvoice(invoice)">
					上传发票
				</view>
			</view>
			
			
		</view>
	</uni-popup>
	
	<!--发货信息-->
	<uni-popup type="center" ref="alertShipment">
		<view class="op-box" style="height:400px;width:500px;">
			<view class="op-title">
				发货
				<view class="op-close" @click="this.$refs.alertShipment.close()">
					<uni-icons type="closeempty" size="20" color="#666"></uni-icons>
				</view>
			</view>
			<view class="sh-content left clearfix">
				<view class="sh-order-no left clearfix">
					订单号：{{shipmentOrder.item.order_no}}
				</view>
				<view class="sh-form-input left clearfix">
					<uni-section title="物流公司" type="line">
						<view class="uni-px-5 uni-pb-5">
							<uni-data-select v-model="expressForm.title" :localdata="express" @change="change"></uni-data-select>
						</view>
					</uni-section>
					
					<uni-section title="运单号" type="line">
						<view class="uni-px-5 uni-pb-5">
							<uni-easyinput v-model="expressForm.number" placeholder="请输入运单号"></uni-easyinput>
						</view>
					</uni-section>
					
					<view class="sh-form-button left" @click="submitExpress">确认发货</view>
				</view>
			</view>
		</view>
	</uni-popup>
	</view>
</template>
<style>
	.uni-select[data-v-ddf9e0a2] {
	    font-size: 14px;
	    border: 1px solid #e5e5e5;
	    box-sizing: border-box;
	    border-radius: 4px;
	    padding: 0 5px;
	    padding-left: 10px;
	    position: relative;
	    display: flex
	;
	    -webkit-user-select: none;
	    user-select: none;
	    flex-direction: row;
	    align-items: center;
	    border-bottom: solid 1px #e5e5e5;
	    width: 100%;
	    flex: 1;
	    height: 45px !important;
	}
</style>
<style scoped lang="scss">
	.menu-so label{line-height:30px;}
	.menu-so{width:300px;height:30px;border:1px solid #eee;margin-top:10px;margin-right:30px;border-radius: 5px;}
	.sh-form-button{width:60%;height:40px;background:#2979ff;line-height:40px;text-align:center;color:#fff;border-radius: 5px;margin-left:20%;margin-top:2rem;font-size:14px;cursor:pointer;}
	.sh-form-input{width:100%;}
	.sh-order-no{font-size:14px;font-weight:400;}
	.sh-content{width:90%;margin-left:5%;height:300px;margin-top:20px;}
	.list-button{width:65px;height:30px;font-size:12px;margin-left:5px;}
	.po-buttom-box{width:60%;height:40px;margin-top:70px;background:#2979ff;line-height:40px;text-align: center;border-radius: 5px;margin-left:20%;color:#fff;cursor:pointer;}
	.order-buttom-price label{margin-left:5px;margin-right:5px;}
	.order-buttom-price{line-height:35px;font-size:14px;}
	.order-buttom-goods-number{width:100px;line-height:35px;font-size:14px;margin-left:30px;}
	.order-buttom-box{width:100%;height:35px;}
	.order-userinfo-content text label{float:left;margin-right:5px;}
	.order-userinfo-content text{float:left;width:calc(100% - 30px);margin-left:10px;line-height:30px;font-size:14px;overflow-wrap: break-word;}
	.order-userinfo-content{width:100%;min-height:70px;padding-bottom:20px;}
	.order-userinfo{width:100%;min-height:100px;background:#f5f5f5;margin-top:10px;}
	.order-goods-right-price{width:70px;line-height:80px;text-align: center;height:80px;color:#ff5000;}
	.order-goods-right-number{width:75px;line-height:80px;color:#999;font-size:14px;}
	.order-goods-text-right{width:150px;height:80px;}
	.order-goods-text-left text{float:left;width:100%;line-height:25px;}
	.order-goods-text-left{width:450px;height:80px;line-height:80px;font-size:14px;color:#333;}
	.order-goods-text{width:calc(100% - 100px);height:80px;margin-top:5px;}
	.order-goods-image{width:80px;height:80px;margin:5px;border-radius: 5px;overflow: hidden;margin-left:10px;}
	.order-goods-list{width:100%;height:90px;margin-bottom:10px;}
	.order-title-right{margin-right:20px;line-height:25px;}
	.order-titles{width:calc(100% - 10px);height:30px;font-size:13px;margin:10px;margin-bottom:0px;}
	.order-goodss{width:100%;min-height:120px;background:#f5f5f5;margin-top:10px;border-radius: 3px;}
	.order-create-date{line-height:35px;font-size:14px;color:#999;margin-right:20px;}
	.order-number{width:250px;height:35px;line-height:35px;margin-left:20px;font-size:14px;color:#666;}
	.order-no{width:100%;height:35px;background:#f5f5f5;border-radius: 3px;}
	.op-submit{width:70%;margin-left:15%;height:35px;line-height:35px;font-size:14px;margin-top:20px;}
	.op-content{width:90%;margin-left:5%;margin-top:20px;float:left;height:700px;overflow:auto;}
	.op-close{width:30px;height:30px;position:absolute;right:0px;top:0;cursor:pointer;}
	.op-title{float:left;width:calc(100% - 20px);line-height:30px;padding-left:20px;margin-top:5px;font-size:15px;font-weight:bold;position: relative;}
	.op-box{width:800px;height:800px;background:#fff;border-radius: 10px;}
	.list-page{width:100%;height:50px;line-height:50px;text-align:center;margin-top:30px;}
	.order-text text{float:left;width:100%;font-size:13px;text-align: left;}
	.order-text{width:240px;height:50px;margin-top:5px;margin-bottom:5px;margin-left:10px;}
	.order-image{width:50px;height:50px;margin-top:5px;margin-bottom:5px;border-radius: 3px;overflow: hidden;}
	.list-button{margin-left:10px;background:#2979ff;color:#fff;}
	.order-goods{width:300px;min-height:50px;margin-left:5px;border-radius: 3px;overflow: hidden;cursor:pointer;}
	.menu-table-content{min-width:1600px;}
	.uni-forms-item__label{width:60px !important;}
	.form-quxiao-submit{width:80px;line-height:35px;height:35px;color:#666;border-radius: 5px;text-align: center;border:1px solid #ccc;margin-right:20px;cursor:pointer;font-size:14px;}
	.form-submit{width:80px;line-height:35px;height:35px;background:#2979ff;color:#fff;border-radius: 5px;text-align: center;margin-right:20px;cursor:pointer;font-size:14px;}
	.add-content{width:80%;margin-left:10%;margin-top:40px;}
	.add-title label:last-child{float:right;line-height:40px;height:40px;margin-right:20px;font-size:14px;color:#333;}
	.add-title label:first-child{float:left;line-height:40px;height:40px;margin-left:20px;font-size:14px;color:#333;font-weight:500;}
	.add-title{width:100%;line-height:40px;height:40px;border-bottom:1px solid #eee;}
	.add-box{width:600px;height:500px;background:#fff;border-radius: 12px;}
	.menu-title label{float:left;margin-right:5px;}
	.menu-title{width:calc(100% - 1500px);height:45px;border-right:1px solid #eee;line-height:45px;text-align:center;font-size:15px;}
	.menu-sort{width:100px;height:45px;line-height:45px;text-align:center;font-size:14px;border-right:1px solid #eee;}
	.menu-tr:hover{background:#f8f8f8;}
	.menu-tr{width:100%;height:45px;border-bottom:1px solid #eee;}
	.menu-table{width:100%;border:1px solid #eee;border-bottom:none;}
</style>

<script>
	var db = uniCloud.database();
	import common from '/static/js/common.js'
	var global = uniCloud.importObject('global',{customUI:true});
	export default {
		name:"system-menu",
		data() {
			return {
				keyword:'',
				expressForm:{
					title:'',
					number:''
				},
				express:[
					{
						text:'顺丰速运',
						value:'顺丰快递',
						com:'shunfeng'
					},
					{
						text:'顺丰快运',
						value:'顺丰快运',
						com:'shunfengkuaiyun'
					},
					{
						text:'京东物流',
						value:'京东物流',
						com:'jd'
					},
					{
						text:'京东快运',
						value:'京东快运',
						com:'jingdongkuaiyun'
					}
					],
				invoicePercent:0,
				invoice:{},//发票信息
				total:10,
				data:[],
				shipmentOrder:{},
				currentOrder:{},
				routes: [
				        {
				          to: "/A",
				          name: "订单管理",
				        },
				        {
				          to: "/B",
				          name: "待发货订单",
				        }
				      ]
			};
		},
		mounted() {
			var that = this;
			this.getData();
		},
		props:['currentPage'],
		methods:{
			//切换物流公司以后
			change(e){
				var index = this.express.findIndex((item)=>{
					return item.value == e;
				})
				
				this.expressForm.com = this.express[index].com;
			},
			//搜索
			submitSearch(){
				this.getData();
			},
			//提交发货
			submitExpress(){
				var that = this;
				var data = this.expressForm;
				var order = this.shipmentOrder;
				var express = order.item.delivery;
				if(!data.title){
					uni.showToast({
						title:'请选择快递公司',
						icon:'none'
					})
					return false;
				}
				if(!data.number){
					uni.showToast({
						title:'请输入运单号',
						icon:'none'
					})
					return false;
				}
				data.create_date = new Date().getTime();
				if(express && express.title && express.number){
					//修改快递信息
					db.collection('order').where({order_no:order.item.order_no}).update({delivery:data}).then(res=>{
						uni.showToast({
							title:'修改成功'
						})
						this.data[order.index].delivery = data;
						this.data[order.index].status_code = 2;
						this.$refs.alertShipment.close();
					});
				}else{
					db.collection('order').where({order_no:order.item.order_no}).update({delivery:data,status_code:2}).then(res=>{
						//更新发货状态数组
						that.updateOrderStatus(order.item.order_no,{code:2,text:'待收货',create_date:new Date().getTime()});
						uni.showToast({
							title:'发货成功'
						})
						this.data[order.index].delivery = data;
						this.data[order.index].status_code = 2;
						this.$refs.alertShipment.close();
					});
				}
			},
			//更新订单状态为已发货
			updateOrderStatus(orderNo,data){
				global.updateOrderStatus(orderNo,data).then(res=>{
					console.log('更新结果',res);
				}).catch(err=>{
					console.log('更新失败',err);
				})
			},
			//发货
			shipment(item,index){
				if(item.delivery && item.delivery.title && item.delivery.number){
					this.expressForm = item.delivery;
				}else{
					this.expressForm = {
						title:'',
						number:''
					}
				}
				this.shipmentOrder = {
					item:item,
					index:index
				}
				this.$refs.alertShipment.open();
			},
			//上传发票
			uploadInvoice(item){
				var that = this;
				uni.chooseFile({
				  count: 1, //默认100
					success: function (res) {
						var filePath = res.tempFilePaths[0];
						var title = res.tempFiles[0].name;
						var fileName = common.generateUUIDWithExtension(title);
						uniCloud.uploadFile({
						        filePath: filePath,
						        cloudPath: fileName,
						        onUploadProgress: function(progressEvent) {
						          var percentCompleted = Math.round(
						            (progressEvent.loaded * 100) / progressEvent.total
						          );
								that.invoicePercent =  percentCompleted;
						        },
						        success(result) {
									uni.showToast({
										title:'上传成功'
									})
									//更新到对应的记录
									db.collection('order').where({_id:item._id}).update({
										"invoice_url":{
											url:result.fileID,
											title:title
										},
										is_invoice:true
									}).then(URes=>{
										that.invoice.is_invoice = true;
									}).catch(UErr=>{
										console.log('更新失败',UErr);
									});
								}
						      });
					}
				});
			},
			//弹出发票弹窗
			alertInvoice(item,index){
				this.invoice = item;
				this.$refs.alertInvoice.open();
			},
			formatPhone(phone, showAll = false) {
			  // 先将输入转换为字符串并去除所有非数字字符
			  const phoneStr = String(phone).replace(/\D/g, '');
			  
			  // 验证手机号格式（11位数字）
			  if (!/^\d{11}$/.test(phoneStr)) {
			    console.warn('手机号格式不正确');
			    return phone; // 格式错误时返回原始值
			  }
			  
			  // 提取手机号的前三位、中间四位和后四位
			  const prefix = phoneStr.slice(0, 3);
			  const middle = phoneStr.slice(3, 7);
			  const suffix = phoneStr.slice(7, 11);
			  
			  // 根据showAll参数决定中间部分的显示方式
			  return showAll 
			    ? `${prefix} ${middle} ${suffix}`  // 138 1234 5678
			    : `${prefix} **** ${suffix}`;     // 138 **** 5678
			},
			//弹出产品详情
			alertGoodsDetail(item,index){
				this.currentOrder = item;
				this.$refs.goodsDetail.open();
			},
			//切换分页后
			changePage(e){
				var page = e.current;
				uni.navigateTo({
					url:'/pages/index/index?page=order-list&p='+page
				})
			},
			copy(text){
				uni.setClipboardData({
					data: text
				});
			},
			//设置显示开关
			setIsshow(event){
				this.formData.is_show = event.detail.value;
			},
			
			
			//删除
			remove(item,index){
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确定要删除吗？',
					success: function (res) {
						if (res.confirm) {
							if(item && item._id && item._id.length > 5){
								db.collection('navigator-menu').where({_id:item._id}).remove().then(result=>{
									that.menu.splice(index,1);
								});
							}
							
						}
					}
				});
			},
			//获取菜单列表
			getData(){
				var page = this.currentPage;
				var keyword = this.keyword;
				if(!page || page < 1){
					page = 1;
				}
				uni.showLoading({
					title:'加载中'
				})
				var where = {}
				if(keyword){
					 page = 1;
					// 使用数据库的模糊查询语法，%表示任意字符
					where = {
					    $and: [
					        {
					          $or: [
					            { order_no: keyword },
					            { 'goods.cartList.param.model': { $regex: keyword, $options: 'i' } },
					            { 'goods.cartList.goods_title': { $regex: keyword, $options: 'i' } },
					            { 'address.mobile': { $regex: keyword, $options: 'i' } },
					            { 'address.name': { $regex: keyword, $options: 'i' } }
					          ]
					        },
					        { status_code: 1 }
					      ]
					};
					
				}else{
					where = {
						status_code: 1
					}
				}
				var skip = (page - 1) * 10;
				db.collection('order').orderBy('create_date desc').where(where).skip(skip).limit(10).get({getCount:true}).then(res=>{
					uni.hideLoading();
					this.data = res.result.data;
					this.total = res.result.count;
				}).catch(err=>{
					uni.hideLoading();
				});
			}
		}
	}
</script>
